package net.chromedpork.hypertext.filtration;



import net.chromedpork.hypertext.validation.Assertion;



/**
 *
 *  The filter object fabricator.
 * 
 *  @author Inode <inode@chromedpork.net>
 *
 */

public class FilterFactory
{
    /**
     *
     *  Generate a Map filter object with preconfigured key and value
     *  XPath expression fields.
     *
     *  @param keyXPath     XPath expression for enumerating key data
     *  @param valueXPath   XPath expression for enumerating value data
     *
     *  @return Map filter object
     *
     */

    public static Filter getMapFilter(String keyXPath,
                                      String valueXPath)
    {
        Assertion.notNull(keyXPath, "key XPath is null");
        Assertion.notNull(valueXPath, "value XPath is null");

        return (new MapFilterObject(keyXPath, valueXPath));
    }


    /**
     *
     *  Generate a Map filter object with preconfigured key and value
     *  XPath expression fields, as well as the name of an attribute that
     *  should feature in tags matched by the value XPath, whose value should
     *  be used in the respective KV pair.
     *
     *  @param keyXPath         XPath expression for enumerating key data
     *  @param valueXPath       XPath expression for enumerating value data
     *  @param returnAttribute  name of tag attribute whose value is required
     *
     *  @return Map filter object
     *
     */
    
    public static Filter getMapFilter(String keyXPath,
                                      String valueXPath,
                                      String returnAttribute)
    {
        Assertion.notNull(keyXPath, "key XPath is null");
        Assertion.notNull(valueXPath, "value XPath is null");
        Assertion.notNull(returnAttribute, "return attribute is null");

        return (new MapFilterObject(keyXPath, valueXPath, returnAttribute));
    }



    /**
     *
     *  Generate a Map filter object with preconfigured element XPath
     *  expression field.
     *
     *  @param elementXPath   XPath expression for enumerating element data
     *
     *  @return List filter object
     *
     */

    public static Filter getListFilter(String elementXPath)
    {
        Assertion.notNull(elementXPath, "element XPath is null");

        return (new ListFilterObject(elementXPath));
    }



    /**
     *
     *  Generate a Map filter object with preconfigured element XPath
     *  expression field, as well as the name of an attribute that should
     *  feature in tags matched by the element XPath, whose value should
     *  be added to the list.
     *
     *  @param elementXPath   XPath expression for enumerating element data
     *  @param returnAttribute  name of tag attribute whose value is required
     *
     *  @return List filter object
     *
     */
    
    public static Filter getListFilter(String elementXPath,
                                       String returnAttribute)
    {
        Assertion.notNull(elementXPath, "element XPath is null");
        Assertion.notNull(returnAttribute, "return attribute is null");

        return (new ListFilterObject(elementXPath, returnAttribute));
    }
}
